package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.TableTypeClient;
import com.woniuxy.store.client.param.tableParam.AddTableTypeParams;
import com.woniuxy.store.client.param.tableParam.ModifyTableTypeParams;
import com.woniuxy.table.client.TableTypeMannageClient;
import com.woniuxy.table.client.TableTypeQueryClient;
import com.woniuxy.table.client.param.AddTableTypeParam;
import com.woniuxy.table.client.param.ModifyTableTypeParam;
import com.woniuxy.table.client.result.DinnerTableTypeClientDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RestController
@RequestMapping("/store/table")
public class TableTypeClientImpl implements TableTypeClient {
    @Autowired
    private TableTypeMannageClient tableTypeMannageClient;
    @Autowired
    private TableTypeQueryClient tableTypeQueryClient;
    @Override
    public Result addTableType(@Valid AddTableTypeParams addTableTypeParams) {
        AddTableTypeParam addTableTypeParam = BeanUtil.toBean(addTableTypeParams, AddTableTypeParam.class);
        addTableTypeParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = tableTypeMannageClient.addTableType(addTableTypeParam);
        return result;
    }

    @Override
    public Result modifyTableType(@Valid ModifyTableTypeParams modifyTableTypeParams) {
        ModifyTableTypeParam modifyTableTypeParam = BeanUtil.toBean(modifyTableTypeParams, ModifyTableTypeParam.class);
        modifyTableTypeParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = tableTypeMannageClient.modifyTableType(modifyTableTypeParam);
        return result;
    }

    @Override
    public Result deleteTableType(Integer tableTypeId) {
        Result result = tableTypeMannageClient.deleteTableType(StoreIdUtil.getFromToken(), tableTypeId);
        return result;
    }

    @Override
    public Result getTableType(Integer tableTypeId) {
        Result<DinnerTableTypeClientDto> tableType = tableTypeQueryClient.getTableType(StoreIdUtil.getFromToken(), tableTypeId);
        return tableType;
    }

    @Override
    public Result getAllTableType() {
        return tableTypeQueryClient.getAllTableType(StoreIdUtil.getFromToken());
    }


}
